import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        System.out.println("水仙花数有：");
        for (int i = 0; i < 999999999; i++) {
            int temp = i;
            int count = 0;

            //先判断i的位数
            while (temp != 0){
                temp /= 10;
                count++;
            }

            //判断是否是水仙花数
            temp = i;
            int sum = 0;
            for (int j = 0; j < count; j++) {
                int a = temp%10;
                sum += Math.pow(a,count);
                temp /= 10;
            }
            if(sum == i){
                System.out.println(i);
            }
        }
    }

    //判断素数改进
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要判断的数：");
        int num = scanner.nextInt();

        int i = 0;
        for (i = 2; i <= Math.sqrt(num); i++) {
            if(num%i == 0){
                System.out.println(num + "不是素数");
                break;
            }
        }

        if(i > Math.sqrt(num)){
            System.out.println(num + "是素数");
        }
    }

    //打印数据改进
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入：");
        int num = scanner.nextInt();

        for (int i = 0; i < num; i++) {
            for (int j = 0; j < num; j++) {
                if(i==j){
                    System.out.print("*");
                }else if(i+j==num-1){
                    System.out.print("*");
                }else{
                    System.out.print(" ");
                }
            }
            System.out.print("\n");
        }
    }

    //判断水仙花数
    public static void main3(String[] args) {
        System.out.println("水仙花数有：");
        for (int i = 0; i < 999999999; i++) {
            int temp = i;
            int count = 0;

            //先判断i的位数
            while (temp != 0){
                temp /= 10;
                count++;
            }

            //判断是否是水仙花数
            temp = i;
            int sum = 0;
            for (int j = 0; j < count; j++) {
                int a = temp%10;
                sum += Math.pow(a,count);
                temp /= 10;
            }
            if(sum == i){
                System.out.println(i);
            }
        }
    }

    /*创建方法求两个数的最大值max2，
      随后再写一个求3个数的最大值的函数max3
      要求：在max3这个函数中，调用max2函数，来实现3个数的最大值计算
     */
    //判断两个数中最大值
    public static int max2(int a,int b){
        if(a >= b){
            return a;
        }else {
            return b;
        }
    }

    //判断三个数中最大值
    public static int max3(int a,int b,int c){
        if(max2(a,b) > c){
            return max2(a,b);
        } else {
            return c;
        }
    }

    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要判断的两个数：");
        int a = scanner.nextInt();
        scanner.nextLine();
        int b = scanner.nextInt();
        System.out.println("最大值是：" + max2(a,b));
        System.out.println("请输入要判断的三个数：");
        int x = scanner.nextInt();
        scanner.nextLine();
        int y = scanner.nextInt();
        scanner.nextLine();
        int z = scanner.nextInt();
        System.out.println("最大值是：" + max3(x,y,z));
        scanner.close();
    }


    /*
     求 N 的阶乘
     */
    public static int fac1(int n){
        if (n > 1) {
            return n*fac(n-1);
        }else {
            return 1;
        }
    }

    public static void main5(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要计算阶乘的数：");
        int n = scanner.nextInt();
        System.out.println(n + "的阶乘是" + fac1(n));
        scanner.close();
    }

    /*
    求1！+2！+3！+4！+........+n!的和
     */
    public static int fac(int n){
        if (n > 1) {
            return n*fac(n-1);
        }else {
            return 1;
        }
    }

    public static int sum(int n){
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += fac(i);
        }
        return sum;
    }

    public static void main6(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要计算阶乘和的数：");
        int n = scanner.nextInt();
        System.out.println("阶乘和是" + sum(n));
        scanner.close();
    }

    /*
    求斐波那契数列的第n项。(迭代实现)
     */
    public static int fab(int n){
        if(n == 1){
            return 1;
        } else if (n == 2) {
            return 1;
        }else {
            return fab(n-1) + fac(n-2);
        }
    }

    public static void main7(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要求的项数：");
        int n = scanner.nextInt();
        System.out.println("第"+ n + "项是" + fab(n));
        scanner.close();
    }

    /*
    求和的重载
    在同一个类中,分别定义求两个整数的方法 和 三个小数之和的方法。 并执行代码，求出结果
     */
    public static int summary(int a,int b){
        return a+b;
    }

    public static float summary(float a,float b,float c){
        return a+b+c;
    }

    public static void main8(String[] args) {
        System.out.println("两个整数之和是" + summary(56,78));
        System.out.println("三个小数之和是" + summary(34.4F,67.4F,64.3F));
    }

    /*
    求最大值方法的重载
    在同一个类中定义多个方法：要求不仅可以求2个整数的最大值，还可以求3个小数的最大值？
     */
    public static int max(int a,int b){
        if (a >= b){
            return a;
        }else {
            return b;
        }
    }

    public static float max(float a,float b){
        if (a >= b){
            return a;
        }else {
            return b;
        }
    }

    public static float max(float a,float b,float c){
        if(max(a,b)>c){
            return max(a,b);
        }else {
            return c;
        }
    }

    public static void main9(String[] args) {
        System.out.println("34,25中最大值是" + max(34,25));
        System.out.println("45.6,78.9,45.5中最大值是" + max(45.6f,78.9f,45.5f));
    }
}